package com.example.kotin.myfragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class MainActivity extends AppCompatActivity {
    private int[] icons = {R.drawable.card_bule_bg,R.drawable.card_bule_bg,R.drawable.card_bule_bg, R.drawable.card_red_bg, R.drawable.card_green_bg, R.drawable.card_bule_bg, R.drawable.card_green_bg, R.drawable.card_red_bg, R.drawable.card_bule_bg};
    private RecyclerView mRecy;
    private List<MoreTypeBean> mData;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        initAdapter();
    }

    private void initView() {
        mRecy = findViewById(R.id.act_recycler_variety_recycler);
    }

    private void initData() {
        mData = new ArrayList<>();
//        随机数 用来标记item界面的类型
        Random random = new Random();

        for (int i = 0; i < icons.length; i++) {
            MoreTypeBean more = new MoreTypeBean();

            more.pic = icons[i];
            more.type = random.nextInt(3);
            mData.add(more);
        }
    }

    private void initAdapter() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        mRecy.setLayoutManager(linearLayoutManager);
        RecyclerMultiAdapter adapter = new RecyclerMultiAdapter(mData);
        mRecy.setAdapter(adapter);

       /* ScaleAnimation scaleXY = AnimationUtils.scaleXY();
        mRecy.startAnimation(scaleXY);
        scaleXY.start();*/


        adapter.setOItemClick(new ItemClickListener() {
            @Override
            public void onClickListener(View view, int position) {
                Toast.makeText(MainActivity.this,"点击了"+position,Toast.LENGTH_SHORT).show();
            }
        });
    }
}
